#ifndef __APP_ATT7022EU_H
#define __APP_ATT7022EU_H

#include "app_config.h"

#define PILE_HEAD    0
#define PHASE_A			 1
#define PHASE_B			 2
#define PHASE_C			 3

#define TYPE_LOSS_PWR 0xEB
#define TYPE_RE_PWR   0xFF

#define AC_POWER_PIN     GET_PIN(A,1)

#define ATT7022EU_RST_PIN  GET_PIN(B,12)

#define ATT7022EU_REG_ID   					0x00
#define ATT7022EU_REG_RST  					0xD3
#define ATT7022EU_DATA_RST 					0x00

//#define ATT7022EU_DEV    					  "spi20"  

typedef struct line_data//下桩头采集数据
{
	rt_uint32_t vol_value;					//电压数据
	rt_uint32_t vol_alarm_count;		//电压报警计数
	rt_uint32_t vol_recover_count;	//电压恢复计数	
	rt_uint32_t vol_alarm_send;			//电压发送报警
	rt_uint32_t vol_already_alarm;	//电压已报警标志
	rt_uint32_t vol_alarm_timer_sta;//电压报警定时器状态
	rt_uint8_t  vol_start_alarm_sta;//重发电压报警状态
	rt_uint32_t cur_value;					//漏电流数据
	rt_uint32_t cur_alarm_value;		//漏电报警数据
	rt_uint32_t cur_already_alarm;	//漏电已报警标志
	rt_uint32_t cur_recover_count;  //漏电恢复计数
	rt_uint32_t cur_alarm_count;  //漏电报警计数
	time_t 			vol_alarm_time;		  //电压报警时间
}line_data;

typedef struct total_protect_data//总保数据
{
	rt_uint32_t 	  checksum_first;					//第一个校验值
	rt_uint32_t 	  checksum_second;				//第二个校验值
	line_data 		  get_line_data[4]; 			//总保数据
}total_protect_data;

//typedef struct vol_start
//{
//	rt_uint8_t voldev_resend;
//	rt_uint8_t vol_resend[3];
//}vol_start; 

typedef struct vol_dev_sta
{
	rt_uint32_t loss_vol_count;
}vol_dev_sta;

rt_uint32_t att7022eu_read(struct rt_spi_device *dev,rt_uint8_t reg);

int app_init_att7022eu(void);
#endif

